﻿<style>
    .table2 .layui-table-cell {
        height: 26px;
        font-size: 0.9em;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-listsel">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">关键字</label>
                    <div class="layui-input-inline">
                        <input type="text" name="key" id="key" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label">县/区</label>
                    <div class="layui-input-inline">
                        <select id="selarea" name="selarea">
                            <option value=""></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-listsel" lay-submit lay-filter="LAY-app-contlist-searchsel">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body table2">
            <div style="padding-bottom: 10px;">
                <script type="text/html" template lay-done="layui.data.setActive2()">
                    <span>当前选中商品：</span>
                    <span id="spmc" style="color:#2F4056;font-weight:bold">----</span>
                    <span> &nbsp;&nbsp;&nbsp;</span>
                    <!--<span id="spsl" style="color:red;font-weight:bold;font-size:1.2em">8</span>-->
                    <span>将上架到下列选中店铺。 &nbsp;&nbsp;&nbsp;</span>
                    <button class="layui-btn layui-btn-sm layuiadmin-btn-listsel" data-type="sure">确认选品</button>
                </script>
            </div>
            <table id="LAY-app-content-listsel" lay-filter="LAY-app-content-listsel"></table>
        </div>
        <div id="xpresult">
            
        </div>
    </div>
</div>
<script>

    layui.use(['admin', 'table','form'], function () {

        var $ = layui.$
        , admin = layui.admin
        , view = layui.view
        , table = layui.table
        , form = layui.form;

        admin.req({
            url: layui.setter.APIUrl + '/shop/StoreareaMgr/customerQuery', //实际使用请改成服务端真实接口
            type: 'post',
            done: function (res) {
                layui.each(res.Data, function (index, eachdata) {
                    $("#selarea").append("<option value='" + eachdata.Name + "'>" + eachdata.Name + "</option>");
                });
                form.render('select');
            }
        });

        form.render(null, 'app-content-listsel');



        var varButtonRight = "";
        //文章管理
        table.render({
            elem: '#LAY-app-content-listsel'
            , toolbar: false  //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , defaultToolbar: ['filter']
            , method: "post"
            , url: layui.setter.APIUrl + '/shop/storeMgr/listPainToGood?GoodID=' + GoodID + "&SupplierID=" + SupplierID
            , headers: { //通过 request 头传递
                Authorization: "bearer " + layui.data('layuiAdmin').access_token
            }
            , parseData: function (res) { //res 即为原始返回的数据 
                varButtonRight = res.Data.ButtonRight;
                return {
                    "ResultCode": res.ResultCode, //解析接口状态
                    "ResultInfo": res.ResultInfo, //解析提示文本
                    "count": res.Data.TotalRecordCount, //解析数据长度
                    "Data": res.Data.Items //解析数据列表 
                };
            }
        , cols: [[
          { type: 'checkbox', fixed: 'left', field: 'PID' }, //sort: true  //hide: true //  width:100
            { field: 'Area', title: '县/区' },
            { field: 'Name', title: '店铺名称', minWidth: 180 },
            { field: 'Code', title: '店铺编码' },
            //{ field: 'UserName', title: '联系人' },
            //{ field: 'Phone', title: '联系电话' },
            {
                field: 'IsSelectGood', title: '选品状态', templet: function (d) {
                    var html = "";
                    if (d.IsSelectGood == 0) {
                        html = "<span style='color:#c2c2c2;font-weight:bold'>未选品</span>";
                    } else {
                        html = "<span style='color:#393D49;font-weight:bold'>已选品</span>";
                    }
                    return html;
                }
            },
        ]]
        , page: true
        , limit: 10
        , limits: [10, 25, 50, 75, 100]
        , text: {
            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增 text: '对不起，加载出现异常！'
        }
        });
        

        //监听搜索
        form.on('submit(LAY-app-contlist-searchsel)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-app-content-listsel', {
                where: field,
                page:{
                    curr:1 //重新从第1页开始
                }
            });
        });

    });

    layui.data.setActive2 = function () {

        layui.use(['form', 'admin', 'table'], function () {
                var $ = layui.$;
                var form = layui.form;
                var admin = layui.admin;
                var view = layui.view;
                var table = layui.table;

                $("#spmc").text(GoodName);

                var active = {
                    sure: function () {
                        var checkStatus = table.checkStatus('LAY-app-content-listsel')
                        , checkData = checkStatus.data; //得到选中的数据

                        if (checkData.length === 0) {
                            return layer.msg('请选择店铺');
                        }
                        var checkStoreIds = [];
                        var tip = "";
                        $.each(checkData, function (index, eobj) {
                            if (eobj.IsSelectGood == 1) {
                                tip = "请勿选择已选品店铺";
                            }else{
                                checkStoreIds.push(eobj.PID);
                            }
                        });
                        if (tip != "") {
                            return layer.msg(tip);
                        }

                        var StoreIds = JSON.stringify(checkStoreIds);
                        layer.confirm('确定选品吗？确认后商品将同步到店铺。', function (index) {
                            var index9 = layer.load(1);
                            admin.req({
                                url: layui.setter.APIUrl + '/shop/Goods_baseMgr/GoodUpperToStore' //实际使用请改成服务端真实接口
                              , data: { "GoodId": GoodID, "StoreIds": StoreIds }
                                  , type: "post"
                              , done: function (res) {
                                  debugger;
                                  layer.close(index9); //执行关闭
                                  layer.close(index); //执行关闭
                                  layer.msg("提交成功，选品结果展示在表格下方，请注意查看！");
                                  $("#xpresult").html(res.ResultInfo);
                                  table.reload('LAY-app-content-listsel');
                              }
                            });
                        });
                    }
                };

                 $('.layui-btn.layuiadmin-btn-listsel').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    }

</script>
